package com.example.administrator.myapplication;

import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.administrator.myapplication.chat.Print;

/**
 * Created by Administrator on 2018/11/20.
 */

public class Mss extends AppCompatActivity implements View.OnClickListener {
    TextView textView2;
    Button button4,button5,button6;
    Intent intent;
    Mservice.Mbinder mbinder;
    private ServiceConnection connection=new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            Print.string("activity  service   连接成功回调方法");
            mbinder= (Mservice.Mbinder) service;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            Print.string("activity   service   断开连接--------");

        }
    };
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac);

        textView2=findViewById(R.id.textView2);
        button4=findViewById(R.id.button4);
        button5=findViewById(R.id.button5);
        button6=findViewById(R.id.button6);

        button4.setOnClickListener(this);
        button5.setOnClickListener(this);
        button6.setOnClickListener(this);

       intent=new Intent(Mss.this,Mservice.class);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button4:
//                startService(intent);
               bindService(intent,connection, Service.BIND_AUTO_CREATE);
                break;
            case R.id.button5:
//                stopService(intent);
                Print.string("int ___"+mbinder.getInt());
                break;
            case R.id.button6:
               unbindService(connection);
                break;
        }

    }
}
